<?php
#============================
#	Filename: class_permission.php
#	Note	: 权限验证类
#	Version : 1.0
#	Author  : prettyOrange
#	Update  : 2012-02-11
#============================
class class_permission
{
	/*根据权限码获得具有此权限用户列表*/
	public static function GetUsersByNodeID($nodeID)
	{
		$user_list = $_ENV['db']->fetchAll("SELECT m.username,m.nickname,m.uid FROM `admincp_member` as m LEFT JOIN admincp_member_perm as p ON m.uid=p.uid WHERE p.node_id = '{$nodeID}'");
		return $user_list;
	}
	
	/*验证某一用户是否有某一权限*/
	public static function ValidateNodeByUser($nodeID,$userID)
	{
		$flog = true;
		if (!$_ENV['db']->fetchCol("SELECT node_id FROM admincp_member_perm WHERE node_id = '{$nodeID}' AND uid = '{$userID}'")) 
		{
         	$flog = false;
        }
		return $flog;
	}
	
	/*[返回某用户对某一权限]*/
	public static function GetNodeByUser($nodeID,$userID)
	{
		$audit_member = $_ENV['db']->fetch("SELECT m.uid,m.username,m.nickname FROM admincp_member as m LEFT JOIN admincp_member_perm as p ON m.uid=p.uid WHERE p.node_id = '{$nodeID}' AND m.uid='{$userID}'"); 
		return $audit_member;
	}
	
	public static function GetUsersByNodes($nodeIDs)
	{
		//echo "SELECT m.username,m.nickname,m.uid,p.node_id FROM admincp_member_perm as p left JOIN admincp_member as m on m.uid=p.uid WHERE p.node_id IN (". $nodeIDs .") order by p.node_id";
		 return $_ENV['db']->fetchAll("SELECT m.username,m.nickname,m.uid,p.node_id FROM admincp_member_perm as p left JOIN admincp_member as m on m.uid=p.uid WHERE p.node_id IN (". $nodeIDs .") order by p.node_id");
	}
}
?>